/**
 * SX函数库
 * 官网：xueluo.cn
 * 创建：2019-11-05
 * 更新：2022-10-21
 * 版权声明：该版权完全归xueluo.cn官方所有，可转载使用和学习，但请务必保留版权信息
 */
'use strict';
window.SX = function(str, obj){
	return new SX.init(str, obj);
};
//加载完执行
SX.ready = (function(){
	var f = [], r = false, a = 'addEventListener';
	function handler(e){
		if (r || (e.type === 'onreadystatechange' && document.readyState !== 'complete')) return;
		for (var i = 0; i < f.length; i++) f[i].call(document);
		r = true, f = null;
	}
	document[a]('DOMContentLoaded', handler, false);
	window[a]('load', handler, false);
	return function ready(fn){ r ? fn.call(document) : f.push(fn) };
})();
/**
 * 选择器
 * @param string|function str 节点或者function(ready方式)
 * @param object obj 需要选择该对象下的节点
 * @return object|void
 */
SX.init = function(str, obj){
	this.length = 0;
	obj = obj ? obj : document;
	obj = Object.prototype.toString.call(obj) == '[object HTMLFormElement]' ? [obj] : obj;
	if (typeof str == 'string'){
		if (obj.length){
			var arr = [];
			for (var i = 0; i < obj.length; i++){
				var el = obj[i].querySelectorAll(str);
				if (el[0]){
					for (var s = 0; s < el.length; s++){
						arr.push(el[s]);
					}
				}
			}
			return SX.elThat(this, arr);
		} else {
			return SX.elThat(this, obj.querySelectorAll(str));
		}
	}
	if (typeof str == 'object') return SX.elThat(this, str);
	if (typeof str == 'function') return SX.ready(str);
	return SX.elThat(this, obj.querySelectorAll(str));
};
//继承方法
SX.init.prototype = {
	//遍历
	each(fn){
		return SX.each(this, fn)
	},
	//选择某个dom
	i(s){
		return SX(this[s]);
	},
	//获取value值
	val(v){
		return SX.val(this, v);
	},
	//获取或设置html
	html(v){
		return SX.html(this, v)
	},
	//获取表单
	form(){
		return SX.form(this);
	},
	//子元素的最后追加元素
	append(html){
		return SX.append(this, html)
	},
	//获取css设置的样式属性
	getCss(attr){
		return SX.getCss(this, attr)
	},
	//删除对象
	del(){
		return SX.del(this)
	},
	//获取对象距离屏幕的偏移量
	offset(){
		return SX.offset(this)
	},
	//设置或获取对象style的属性值
	style(name, v){
		return SX.style(this, name, v)
	},
	//设置或获取对象Attribute的属性值
	attr(name, v){
		return SX.attr(this, name, v)
	},
	//删除attr
	delAttr(name){
		return SX.delAttr(this, name)
	},
	//删除对象class
	delCss(name){
		return SX.delCss(this, name)
	},
	//克隆
	clone(){
		return SX.clone(this)
	},
	//给对象添加点击事件
	click(fn){
		return SX.click(this, fn)
	},
	//给对象添加事件
	on(type, fn, bool){
		return SX.on(this, type, fn, bool)
	},
	//方法返回被选元素的后代元素
	find(name){
		return SX.find(this, name);
	},
	//给对象添加class
	addCss(name){
		return SX.addCss(this, name)
	},
	//判断对象是否存在class
	hasCss(name){
		return SX.hasCss(this, name)
	},
	//如果对象存在指定的css，则删除，不存在则创建
	toggleCss(nameA, nameB, fnA, fnB){
		return SX.toggleCss(this, nameA, nameB, fnA, fnB)
	},
	//显示对象
	show(){
		return SX.show(this)
	},
	//隐藏对象
	hide(){
		return SX.hide(this)
	},
	//隐藏和显示对象
	toggle(fnA, fnB){
		return SX.toggle(this, fnA, fnB)
	},
	animate(json, options){
		return SX.animate(this, json, options)
	}
};
SX.__proto__ = {
	//判断是否为function对象
	isFunction(obj){
		return typeof obj === 'function' && typeof obj.nodeType !== 'number';
	},
	//判断是否为window对象
	isWindow(obj){
		return obj != null && obj === obj.window;
	},
	//判断是否为array对象
	isArrayLike(obj){
		var length = !!obj && 'length' in obj && obj.length, type = typeof obj;
		if (SX.isFunction(obj) || SX.isWindow(obj)) return false;
		return type === 'array' || length === 0 || typeof length === 'number' && length > 0 && (length - 1) in obj;
	},
	elThat(that, el){
		if (!el || (typeof el == 'object' && el.length === 0) || (typeof el == 'array' && el.length === 0)){
			return that;
		} else {
			if (el.tagName == 'SELECT' || el.tagName == 'FORM'){
				that.length = 1;
				that[0] = el;
			} else if (el.length){
				that.length = el.length;
				for (var i = 0; i < el.length; i++){
					that[i] = el[i];
				}
			} else {
				that.length = 1;
				that[0] = el;
			}
		}
		return that;
	},
	//遍历
	each(el, fn){
		if (SX.isWindow(el)){
			fn.call(el, 0, el);
			return el;
		}
		if (!el) return false;
		var length, i = 0;
		if (SX.isArrayLike(el)){
			length = el.length;
			for (; i < length; i++){
				if (fn.call(el[i], i, el[i], el, length) === false) break;
			}
		} else {
			for (i in el){
				if (fn.call(el[i], i, el[i], el, length) === false) break;
			}
		}
		return el;
	},
	//字符串转dom节点
	toDom(html){
		if (typeof html === 'string'){
			var temp = SX.c('div'), frag = document.createDocumentFragment();
			temp.innerHTML = html;
			while (temp.firstChild){
				frag.appendChild(temp.firstChild);
			}
			return frag;
		} else {
			return html;
		}
	},
	//创建节点
	c(name){
		return document.createElement(name);
	},
	//阻止冒泡
	sp(e){
		window.event ? window.event.cancelBubble = true : (e && e.stopPropagation());
	},
	//阻止默认行为
	pd(e){
		e ? e.preventDefault() : (window.event ? window.event.preventDefault() : '');
	},
	//判断当前设备是否为移动端
	isMobile(){
		return /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;
	},
	//获取网址get的值
	getUrl(name, url){
		url = url || 0;
		var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'), r = url ? url.search.slice(1).match(reg) : window.location.search.slice(1).match(reg);
		if (r != null) return decodeURI(r[2]);
		return null;
	},
	//是否为json字符串
	isJson(str){
		if (typeof str == 'string'){
			try {
				JSON.parse(str);
				return true;
			} catch (e){ }
		}
		return false;
	},
	//AJAX
	ajax(json, data){
		if (typeof json == 'string'){
			json = { url: json };
			if (typeof data == 'string'){
				json.form = data;
			} else {
				json.data = data;
			}
		}
		if (!json || !json.url) return;
		json.type = json.type || 'post';
		json.timeout = json.timeout || 15000;
		json.async = json.async != undefined ? json.async : true;
		json.json = json.json != undefined ? json.json : true;
		return new Promise((resolve, reject) => {
			if (!json.data){
				if (json.form){
					json.data = SX(json.form).form();
				}
			}
			var json2url = function(json){
				var arr = [];
				function arrPush(k, v){ arr.push(k + '=' + encodeURIComponent(v)) }
				for (var name in json){
					if (Array.isArray(json[name])){
						if (typeof json[name][0] == 'object'){
							arrPush(name, SX.obj2str(json[name]));
						} else {
							for (var k in json[name]){
								arrPush(name, json[name][k]);
							}
						}
					} else {
						typeof json[name] == 'object' ? arrPush(name, SX.obj2str(json[name])) : arrPush(name, json[name]);
					}
				}
				return arr.join('&');
			}
			//创建
			var xhr = new XMLHttpRequest();
			//连接 和 发送 - 第二步
			switch (json.type.toLowerCase()){
				case 'post':
					xhr.open('POST', json.url, json.async);
					//设置表单提交时的内容类型
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
					if (json.data instanceof FormData == false) xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					if (json.header){
						for (var k in json.header){
							xhr.setRequestHeader(k, json.header[k]);
						}
					}
					xhr.send(json.data instanceof FormData ? json.data : json2url(json.data));
					break;
				default:
					var _data = json2url(json.data), _url = json.url + (_data.length ? (json.url.indexOf('?') > -1 ? '&' : '?') + _data : '');
					xhr.open('GET', _url, json.async);
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
					xhr.send();
					break;
			}
			//接收 - 第三步
			json.loading && json.loading();
			json.timer = setTimeout(function(){
				xhr.onreadystatechange = null;
				json.error && json.error('网络超时。');
				json.complete && json.complete(408);
			}, json.timeout);
			xhr.onreadystatechange = function(){
				if (xhr.readyState == 4){
					clearTimeout(json.timer);
					if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304){
						var res = '';
						if (xhr.responseText.length > 0){
							if (SX.isJson(xhr.responseText)){
								res = json.json ? JSON.parse(xhr.responseText) : xhr.responseText;
							} else {
								res = json.json ? { code: 200, data: xhr.responseText } : xhr.responseText;
							}
						}
						resolve && resolve(res);
						json.success && json.success(res);
						json.complete && json.complete(res);
					} else {
						reject && reject(xhr.status, xhr.responseText);
						json.error && json.error(xhr.status, xhr.responseText);
						json.complete && json.complete(xhr.status, xhr.responseText);
					}
				}
			}
		})
	},
	//按键回调
	keydown(key, callback){
		SX(document).on('keydown', (e) => {
			if (typeof key == 'function'){
				key.call(e, e.keyCode, e);
			} else {
				if ((e.keyCode == key) || (key == undefined)) callback && callback.call(e, e.keyCode, e);
			}
		})
	},
	//子元素的最后追加元素
	append(el, html){
		el = SX.dom2arr(el), html = SX.toDom(html);
		return SX.each(el, function(i,e){
			html = SX.dom2arr(html);
			SX.each(html, function(){
				if (e.nodeType === 1 || e.nodeType === 11 || e.nodeType === 9) e.appendChild(this);
			});
		});
	},
	//获取表单
	form(el){
		el = SX.dom2arr(el);
		var arr = {};
		function init(e){
			if (e.name){
				//针对复选
				if (arr[e.name]){
					if (typeof arr[e.name] != 'object') arr[e.name] = [arr[e.name]];
					arr[e.name].push(e.value);
				} else {
					arr[e.name] = e.value;
				}
			}
		}
		SX.each(el, function(){
			SX('input', this).each(function(){
				if (this.type == 'checkbox'){
					if (this.checked) init(this);
				} else if (this.type == 'radio'){
					if (this.checked) init(this);
				} else {
					init(this);
				}
			});
			SX('textarea', this).each(function(){
				init(this);
			});
			SX('select', this).each(function(){
				if (this.name) arr[this.name] = SX(this).val();
			});
		})
		return arr;
	},
	//显示对象
	show(el){
		el = SX.dom2arr(el);
		return SX.each(el, function(){
			this.style.display = '';
			let d = SX.getCss(this, 'display'), o = SX.getCss(this, 'opacity');
			this.style.opacity = Number(o) == 0 ? 1 : this.style.opacity;
			this.style.display = d == 'none' ? 'initial' : d;
			if (SX.getCss(this, 'visibility') == 'hidden') this.style.visibility = 'visible';
		});
	},
	//隐藏对象
	hide(el){
		el = SX.dom2arr(el);
		return SX.each(el, function(){
			this.style.display = 'none';
		});
	},
	//显示隐藏的元素 或 隐藏显示的元素
	toggle(el, fnA, fnB){
		el = SX.dom2arr(el), fnA = fnA || function(){ }, fnB = fnB || function(){ };
		return SX.each(el, function(i, o){
			if (SX.getCss(this, 'display') == 'none' || SX.getCss(this, 'visibility') == 'hidden'){
				SX.show(this);
				fnA.call(o, i, o);
			} else {
				SX.hide(this);
				fnB.call(o, i, o);
			}
		});
	},
	//获取或设置html
	html(el, v){
		el = SX.dom2arr(el);
		if (typeof v == 'string' || typeof v == 'number'){
			return SX.each(el, function(){
				this.innerHTML = v;
			});
		} else if (typeof v == 'object' && v.tagName){
			return SX.each(el, function(){
				this.appendChild(v);
			});
		} else {
			return el[0] ? el[0].innerHTML : el.innerHTML;
		}
	},
	//对象转为字符串，包括function
	obj2str(obj){
		var a = JSON.stringify(obj, function(key, val){
			if (typeof val === 'function'){
				var str = '`' + val + '`';
				str = str.split('\n').join('FN\\n').split('\t').join('FN\\t');
				return str;
			}
			return val;
		});
		a = a.replace(/("`)|(`")/g, '').replace(/FN\\\\n/g, '\n').replace(/FN\\\\t/g, '\t');
		return a;
	},
	//字符串转为对象
	str2obj(str){
		return eval('(' + str + ')');
	},
	//获取对象距离屏幕的偏移量
	offset(el){
		el = SX.arr2dom(el);
		var e = el, x = e.offsetLeft, y = e.offsetTop;
		while (e = e.offsetParent){
			x += e.offsetLeft;
			y += e.offsetTop;
		}
		return { 'left': x, 'top': y };
	},
	//克隆
	clone(el){
		el = SX.dom2arr(el);
		var node = [];
		SX.each(el, function(){
			node.push(this.cloneNode(true));
		});
		return SX(node);
	},
	//获取css设置的样式属性
	getCss(el, attr){
		el = SX.arr2dom(el);
		return (el.currentStyle || getComputedStyle(el, false))[attr];
	},
	//删除对象
	del(el){
		el = SX.dom2arr(el);
		SX.each(el, function(){
			if (this.parentNode) this.parentNode.removeChild(this)
		});
	},
	//获取选择列表选中的值
	val(el, v){
		if (v != undefined){
			el = SX.dom2arr(el);
			SX.each(el, function(){
				this.selectedIndex = -1;
				if (this.value != undefined) this.value = v;
			});
		} else {
			el = SX.arr2dom(el);
			return el.value != undefined ? el.value : '';
		}
		return el;
	},
	//设置或获取对象style的属性值
	style(el, name, value){
		el = SX.dom2arr(el);
		if (arguments.length == 3 && value){
			//设置一个样式
			return SX.each(el, function(){
				this.style[name] = value;
			});
		} else {
			if (typeof name == 'string'){
				//获取样式
				var that = el;
				return SX.each(el, function(){
					return that.getCss(this, name);
				});
			}
			//批量设置样式
			var json = name;
			return SX.each(el, function(){
				for (var name in json){
					this.style[name] = json[name];
				}
			});
		}
	},
	//设置或获取对象Attribute的属性值
	attr(el, name, value){
		el = SX.dom2arr(el);
		if (value != undefined){
			return SX.each(el, function(){
				this.setAttribute(name, value);
			});
		} else {
			if (typeof name == 'string'){
				el = el[0] ? el[0] : el;
				var a = el.getAttribute ? el.getAttribute(name) : false;
				return a == null ? false : a;
			} else {
				var json = name;
				return SX.each(el, function(){
					for (var name in json){
						this.setAttribute(name, json[name]);
					}
				});
			}
		}
	},
	//删除attr
	delAttr(el, name){
		el = SX.dom2arr(el);
		return SX.each(el, function(){
			this.getAttribute(name) && this.removeAttribute(name);
		});
	},
	//给对象添加点击事件
	click(el, fn){
		el = SX.dom2arr(el);
		return SX.each(el, function(i, o){
			if (fn){
				o.onclick = (e) => fn.call(o, i, o, e);
			} else {
				o.click();
			}
		});
	},
	//给对象添加事件
	on(el, type, fn, bool){
		if (!SX.isWindow(el)) el = SX.dom2arr(el);
		bool = false || bool;
		return SX.each(el, function(i, o){
			o.addEventListener(type, function(e){
				fn.call(o, i, o, e);
			}, bool)
		});
	},
	//对象转为数组对象
	dom2arr(el){
		if (!el || (typeof el == 'object' && el.length === 0) || (typeof el == 'array' && el.length === 0)){
			return [];
		} else {
			if (!el[0]) el = [el];
		}
		return el;
	},
	//多个数组对象，转为第一个对象
	arr2dom(el){
		if (!el || (typeof el == 'object' && el.length === 0) || (typeof el == 'array' && el.length === 0)){
			return false;
		} else {
			if (el[0]) el = el[0];
		}
		return el;
	},
	//返回被选元素的后代元素
	find(el, name){
		el = SX.dom2arr(el);
		return SX(name, el);
	},
	//给对象添加class
	addCss(el, name){
		el = SX.dom2arr(el);
		return SX.each(el, function(){
			var c = this.className.split(/\s+/), n = name.split(/\s+/);
			for (var s of n) !c.includes(s) && c.push(s);
			this.className = c.join(' ');
		});
	},
	//删除对象class
	delCss(el, name){
		el = SX.dom2arr(el);
		return SX.each(el, function(){
			var c = this.className.split(/\s+/), n = name.split(/\s+/);
			for (var s of n) if (c.indexOf(s) > -1) c.splice(c.indexOf(s), 1);
			this.className = c.join(' ');
		});
	},
	//判断对象是否存在class
	hasCss(el, name){
		el = SX.dom2arr(el);
		for (var e of el){
			if (!e.className) return false;
			var css = e.className.split(/\s+/), n = name.split(/\s+/);
			for (var s of n) if (!css.includes(s)) return false;
		}
		return true;
	},
	//如果对象存在指定的css，则删除，不存在则创建
	toggleCss(el, nameA, nameB, fnA, fnB){
		fnA = fnA || function(){ }, fnB = fnB || function(){ }, el = SX.dom2arr(el);
		return SX.each(el, function(i, o){
			var n = nameA.split(' ');
			for (var s of n){
				if (nameB){
					if (SX.hasCss(this, s)){
						SX.delCss(this, s);
						SX.addCss(this, nameB);
						fnB.call(o, i, o);
					} else {
						SX.addCss(this, s);
						SX.delCss(this, nameB);
						fnA.call(o, i, o);
					}
				} else {
					SX.hasCss(this, s) ? SX.delCss(this, s) : SX.addCss(this, s);
				}
			}
		});
	},
	//设置sessionStorage赋值完全等于取值，原生的sessionStorage实际只能存储字符串
	//SX.data() 获取整个sessionStorage
	//SX.data('t1') 获取t1值
	//SX.data('t1',123) 设置t1值
	//SX.data({t1:123,t2:456}) 设置t1和t2值
	//SX.data('t1',{t2:123,t3:456}) 设置t1值，获取后也是该对象
	data(name, value){
		return SX.storage(sessionStorage, name, value);
	},
	storage(type, name, value){
		if (name === undefined) return type;
		if (value === undefined){
			if (typeof name === 'object'){
				name.forEach((v, k) => {
					setData(k, v)
				})
			} else {
				return getData(name);
			}
		}
		if (value !== undefined) setData(name, value);
		function setData(k, v){
			let obj = type.getItem('_SXDataType');
			obj = obj ? SX.str2obj(obj) : {};
			obj[k] = typeof v;
			if (obj[k] === 'object') v = SX.obj2str(v);
			type.setItem(k, v);
			type.setItem('_SXDataType', SX.obj2str(obj));
		}
		function getData(k){
			let v = type.getItem(k), obj = type.getItem('_SXDataType');
			if (obj){
				obj = SX.str2obj(obj);
				if (obj[k] === 'number'){
					return Number(v);
				} else if (obj[k] === 'object'){
					return SX.str2obj(v);
				} else if (obj[k] === 'function'){
					return SX.str2obj(v);
				} else if (obj[k] === 'boolean'){
					return v.toLowerCase() === 'true' ? true : false;
				}
			}
			return v;
		}
	},
	//清除storage
	delStorage(type, name){
		if (name){
			type.removeItem(name);
		} else {
			for (var k in type){
				type.removeItem(k);
			}
		}
	},
	//清除sessionStorage
	delData(name){
		SX.delStorage(sessionStorage, name);
	},
	//设置localStorage赋值完全等于取值，原生的localStorage实际只能存储字符串
	localData(name, value){
		return SX.storage(localStorage, name, value);
	},
	//清除localStorage
	delLocalData(name){
		SX.delStorage(localStorage, name);
	},
	//提示框
	pop(options, time = 2000){
		if (typeof options !== 'object'){
			options = { content: options };
			if (typeof time == 'function'){
				options.success = time, options.time = 2000;
			}
		}
		if (!options.content) return;
		if (options.time !== undefined) time = options.time;
		SX('.pop').del();
		var el = SX.c('div');
		el.className = 'pop ani-up-in';
		el.innerHTML = '<div class="pop-title">' + options.content + '</div>';
		document.body.appendChild(el);
		time > 0 && setTimeout(()=>{
			SX(el).addCss('ani-down-out');
			setTimeout(()=>{
				SX.del(el);
				if (options.url) location.href = options.url;
				options.success && options.success();
			}, 500);
		}, time);
	},
	//弹窗
	alert(options, yes, no){
		if (typeof options == 'string'){
			options = { content: options, btn: ['确认'] };
			if (yes || no) options.btn = 0;
			if (yes) options.yes = yes;
			if (no) options.no = no;
		}
		if (!options.content) return;
		var btn = options.btn || ['取消', '确认'];
		var el = SX.c('div');
		el.className = 'alert';
		document.body.appendChild(el);
		var btnHtml = '<div class="alert-confirm">确定</div><div class="alert-cancel">取消</div>';
		if (btn){
			if (btn[0]) btnHtml = `<div class="alert-confirm">${btn[0]}</div>`;
			if (btn[1]) btnHtml = `<div class="alert-cancel">${btn[0]}</div><div class="alert-confirm">${btn[1]}</div>`;
		}
		el.innerHTML = `<div class="alert-bg"></div>
		<div class="alert-box ani-up-in">
			<div class="alert-content">${options.content}</div>
			<div class="alert-footer">
				${btnHtml}
			</div>
		</div>`;
		SX('.alert-confirm', el).click(function(){
			SX(el).del();
			options.yes && options.yes();
		});
		SX('.alert-cancel', el).click(function(){
			SX(el).del();
			options.no && options.no();
		});
		SX(el).show();
	},
	//顶部对话框
	prompt(options, yes, no){
		if (typeof options == 'string'){
			options = { content: options, btn: ['知道了'] };
			if (yes || no) options.btn = 0;
			if (yes) options.yes = yes;
			if (no) options.no = no;
		}
		if (!options.content) return;
		var btn = options.btn || ['取消', '确认'];
		var title = options.title || '温馨提示';
		var el = SX.c('div');
		el.className = 'prompt';
		document.body.appendChild(el);
		var btnHtml = '<span class="prompt-confirm">确定</span><span class="prompt-cancel">取消</span>';
		if (btn){
			if (btn[0]) btnHtml = `<span class="prompt-confirm">${btn[0]}</span>`;
			if (btn[1]) btnHtml = `<span class="prompt-cancel">${btn[0]}</span><span class="prompt-confirm">${btn[1]}</span>`;
		}
		el.innerHTML = `<div class="prompt-box ani-up-in">
			<div class="prompt-close prompt-cancel">✕</div>
			<div class="prompt-title">「${title}」</div>
			<div class="prompt-content">${options.content}</div>
			<div class="prompt-footer">${btnHtml}</div>
		</div>`;
		SX('.prompt-confirm', el).click(function(){
			SX(el).del();
			options.yes && options.yes();
		});
		SX('.prompt-cancel', el).click(function(){
			SX(el).del();
			options.no && options.no();
		});
		SX(el).show();
	},
	//确认窗
	confirm(url, text){
		url = typeof (url) == 'object' ? url.href : url;
		SX.sp();
		SX.alert({
			content: text,
			yes(){
				window.location.href = url;
			}
		})
		return false;
	}
}

//配置信息
SX.CONF = { URL: '/?' };

//跳转
SX.jump = function(url,bool){
	window.location.href=bool?url:SX.CONF.URL+url;
}

//导入溯雪源
SX.import = function(){
	var el = SX.c('input');
	el.type = 'file';
	el.accept = '.sx';
	el.onchange = function(){
		var formData = new FormData();
		for (var i = 0; i < this.files.length; i++){
			formData.append('file', this.files[i]);
		}
		SX.pop('导入中，请稍等...', 0);
		SX.ajax(SX.CONF.URL + 'import', formData).then(res => {
			if (res.error){
				SX.pop(res.data);
			} else {
				SX.pop('导入成功', ()=>{
					location.reload();
				});
			}
		})
	};
	el.click();
}

//删除文章
SX.delArticle = function(id){
	id = typeof id == 'string' ? [id] : id;
	SX.alert({
		content: '确定要删除吗？',
		yes(){
			SX.ajax(SX.CONF.URL + 'admin/article/delete', { 'id[]': id }).then(()=>{
				SX.pop('删除成功', ()=>{
					location.href = SX.CONF.HOME;
				})
			})
		}
	})
}

//留言回复
SX.reply = function(key){
	SX('input[name=pid]')[0].value = key;
	SX('.comment-replys')[0].innerHTML = '回复：' + SX('.ip-' + key)[0].innerHTML + '<span onclick="SX.cancelReply()">取消</span>';
}

//取消留言回复
SX.cancelReply = function(){
	SX('input[name=pid]')[0].value = '';
	SX('.comment-replys')[0].innerHTML = '';
}

SX(function(){
	//获取配置信息
	if (SX.data('SX.CONF')){
		SX.CONF = SX.data('SX.CONF');
	} else {
		SX.ajax(location.href, { 'getConf': 1 }).then(res => {
			SX.CONF = res.data;
			SX.data('SX.CONF', SX.CONF);
		})
	}
	//返回上一页
	SX('.back').click(()=>{
		window.history.back();
	})
	//后台侧栏收缩
	SX('.toggle-menu').click(()=>{
		SX('.toggle-menu').toggleCss('open');
		SX('.menu').toggleCss('menu-open');
	})
	//菜单按钮高亮显示
	SX('.menu a').each((i, el) => {
		el.className = (el.href == window.location.href || window.location.href.indexOf(el.href) > -1) ? 'active' : '';
	})
	//描述展开显示
	SX('.intro-show').click(function(){
		this.innerHTML = this.innerHTML == '__展开' ? '__收缩' : '__展开';
		SX('textarea[name=intro]').toggle();
	})
	//选项卡
	SX('.tab').each(function(){
		var menu = SX('.tab-menu a', this);
		var content = SX('.tab-content', this);
		if (content.length){
			menu.click((i, el) => {
				menu.delCss('active');
				SX(el).addCss('active');
				content.delCss('active');
				content.i(i).addCss('active');
				SX.pd();
				return false;
			})
		}
	})
});